package com.dd.census.service.impl;

import com.dd.census.entity.Device;
import com.dd.census.mapper.DeviceMapper;
import com.dd.census.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;

/**
 * 业务层实现类
 * Staff1ServiceImpl
 * @author whn
 * @date 2020/11/26
 */
@Service
public class DeviceServiceImpl implements DeviceService {

    @Autowired
	DeviceMapper mapper;

    @Override
    public int insert(Device device) {
        return mapper.insert(device);
    }

    @Override
    public int updateDevice(Device device) {
    	return mapper.updateDevice(device);
    }

	@Override
	public Device selectByKey(String id) {
		return mapper.selectByKey(id);
	}

	@Override
	public Map<String, Object> selectPage(Device device) {
		Map<String, Object> map = new HashMap<String, Object>();
		int total = this.total(device);
		map.put("pageCount", Math.ceil((double) total / device.getPageSize()));// 总页数
		map.put("total", total);// 总条数
		map.put("index", device.getPageIndex());// 当前页
		if (total > 0) {
			device.setPageIndex(device.getPageSize() * (device.getPageIndex() - 1));
			map.put("items", mapper.selectPage(device));
		}
		return map;
	}

	@Override
	public int delete(Device device) {
		return mapper.delete(device);
	}

	@Override
	public int total(Device device) {
		return mapper.total(device);
	}
}